home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / Utils / SWApplication.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  3.8 KB  |  149 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    SWApplication.c
  3. //
  4. //    Portions are Copyright: © 1993 Tony Myles, All rights reserved worldwide.
  5. ///--------------------------------------------------------------------------------------
  6. #ifndef __RESOURCES__
  7. #include <Resources.h>
  8. #endif
  9.  
  10. #ifndef __SPRITEWORLD__
  11. #include <SpriteWorld.h>
  12. #endif
  13.  
  14. #include <Gestalt.h>
  15. #include <Fonts.h>
  16. #include <TextUtils.h>
  17. #include <SWApplication.h>
  18.  
  19.  
  20. ///--------------------------------------------------------------------------------------
  21. //    Initialize
  22. ///--------------------------------------------------------------------------------------
  23.  
  24. void Initialize(short numberOfMasters)
  25. {
  26.     EventRecord tempEvent;
  27.  
  28.     MaxApplZone();
  29.  
  30.     while (numberOfMasters--)
  31.     {
  32.         MoreMasters();
  33.     }
  34.  
  35.     InitGraf(&qd.thePort);
  36.     InitFonts();
  37.     InitWindows();
  38.     InitMenus();
  39.     TEInit();
  40.     InitDialogs(NULL);
  41.     InitCursor();
  42.     FlushEvents(everyEvent, 0);
  43.  
  44.     (void)EventAvail(everyEvent, &tempEvent);
  45.     (void)EventAvail(everyEvent, &tempEvent);
  46.     (void)EventAvail(everyEvent, &tempEvent);
  47. }
  48.  
  49.  
  50. ///--------------------------------------------------------------------------------------
  51. //    ReportError
  52. ///--------------------------------------------------------------------------------------
  53.  
  54. void    ReportError(OSErr err, char* filename, int lineNumber)
  55. {
  56.     SetCursor(&qd.arrow);
  57.     InitCursor();
  58.     
  59.     if (err == memFullErr)
  60.     {
  61.         ErrorAlert(err, filename, lineNumber, kOutOfMemoryStringIndex);
  62.     }
  63.     else if (err == resNotFound)
  64.     {
  65.         ErrorAlert(err, filename, lineNumber, kCantFindResourceStringIndex);
  66.     }
  67.     else
  68.     {
  69.         ErrorAlert(err, filename, lineNumber, kFatalErrorStringIndex);
  70.     }
  71. }
  72.  
  73.  
  74. ///--------------------------------------------------------------------------------------
  75. //    DoCantFindResource
  76. ///--------------------------------------------------------------------------------------
  77.  
  78. void    DoCantFindResource( char* filename, int lineNumber )
  79. {
  80.     OSErr err;
  81.  
  82.     err = ResError();
  83.     
  84.     if (err == noErr)
  85.         err = MemError();
  86.  
  87.         // It's annoying that some toolbox functions, such as GetPicture, don't give
  88.         // ResError OR MemError an error code, nor does the function return any error value. So 
  89.         // you know it failed, but you don't know why. So DoCantFindResource might report
  90.         // a resNotFound error when the resource really does exist, but there simply isn't 
  91.         // enough memory to load it.
  92.     if (err == noErr)
  93.         err = resNotFound;
  94.  
  95.     ErrorAlert(err, filename, lineNumber, kCantFindResourceStringIndex);
  96. }
  97.  
  98.  
  99. ///--------------------------------------------------------------------------------------
  100. //    ErrorAlert
  101. ///--------------------------------------------------------------------------------------
  102.  
  103. void    ErrorAlert(OSErr err, char* filename, int lineNumber, short errorStringIndex)
  104. {
  105.     Str255        messageString, errorString, fileString = "\p", lineString;
  106.     short        n;
  107.  
  108.     GetIndString(messageString, kErrorStringListResID, errorStringIndex);
  109.  
  110.     if (messageString[0] == 0)
  111.     {
  112.         BlockMove(kSeriousDamageString, messageString, sizeof(kSeriousDamageString));
  113.     }
  114.     
  115.     for (n = 0; filename[n] != 0; n++)
  116.     {
  117.         fileString[n+1] = filename[n];
  118.     }
  119.     fileString[0] += n;
  120.  
  121.     NumToString(err, errorString);
  122.     NumToString(lineNumber, lineString);
  123.     ParamText(messageString, fileString, lineString, errorString);
  124.     
  125.         // Call the CleanUpCallBack if there is one.
  126.     if (gSWCleanUpCallBackP != NULL)
  127.         (*gSWCleanUpCallBackP)();
  128.     
  129.     InitCursor();
  130.     (void)StopAlert(kErrorAlertResID, NULL);
  131.     
  132.         // If a CleanUpSpriteWorld is installed, turns its VBL Syncing off.
  133.     if (gSWCleanUpSpriteWorldP != NULL)
  134.         SWSyncSpriteWorldToVBL(gSWCleanUpSpriteWorldP, false);
  135.     
  136.     ExitToShell();
  137. }
  138.  
  139.  
  140. ///--------------------------------------------------------------------------------------
  141. //    CantRunOnThisMachine
  142. ///--------------------------------------------------------------------------------------
  143.  
  144. void    CantRunOnThisMachine( void )
  145. {
  146.     (void)StopAlert(kCantRunAlertResID, NULL);
  147. }
  148.  
  149.